from openpyxl import load_workbook  # 读取excel文件
import logging as log
import utils

# 日志格式化
from bean.user_info_bean import UserInfoBean

log.basicConfig(format='%(asctime)s - [line:%(lineno)d] - %(levelname)s: %(message)s', level=log.info)

# 数据起始行
data_row_start = 2
# 数据终止行
data_row_end = 108


def _user_vital_signs(excel_data, days, types, start_col):
    """
    获取病人生命体征时序数据
    :param excel_data:
    :param days: 数据时序天数
    :param types: 数据类型总数
    :param start_col: 病人生命体征起始列,包含数据第一列
    :return:
    """
    for row_index in range(data_row_start, data_row_end + 1, 1):
        log.info("============================================================开始第" + str(row_index) + "行数据处理")
        # 体温
        log.info("======================开始处理体温数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 0)
        # 心率
        log.info("======================开始处理心率数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 1)
        # # 呼吸评率
        log.info("======================开始处理呼吸评率数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 2)
        # 收缩压
        log.info("======================开始处理收缩压数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 3)
        #  舒张压
        log.info("======================开始处理舒张压数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 4)
        #  平均动脉压
        log.info("======================开始处理平均动脉压数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 5)
        #  休克指数
        log.info("======================开始处理休克指数数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 6)
        #  尿量
        # log.info("======================开始处理尿量数据==========================")
        # utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, data_start, 7)
        # # 摄入量
        # log.info("======================开始处理摄入量数据==========================")
        # utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, data_start, 8)
        # # 输入量
        # log.info("=======================开始处理输入量数据==========================")
        # utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, data_start, 9)


def biochemical_index(excel_data, days, types, start_col):
    """
    处理病人的生化指标
    :param excel_data: excel
    :param days: 数据时序天数
    :param types: 数据类型总数
    :param start_col: 起始列,包含数据第一列
    :return:
    """
    for row_index in range(data_row_start, data_row_end + 1, 1):
        log.info("============================================================开始第" + str(row_index) + "行数据处理")
        # 尿素
        log.info("======================开始处理尿素数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 0)
        # 肌酐
        log.info("======================开始处理肌酐数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 1)
        # 血糖
        log.info("======================开始处理血糖数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 2)
        # 白蛋白
        log.info("======================开始处理白蛋白数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 3)
        # 天门冬氨酸氨基转移酶
        log.info("======================开始处理天门冬氨酸氨基转移酶数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 4)
        # 丙氨酸氨基转移酶
        log.info("======================开始处理丙氨酸氨基转移酶数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 5)
        # 总胆红素
        log.info("======================开始处理总胆红素数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 6)
        # 降钙素原
        log.info("======================开始处理降钙素原数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 7)
        # 白细胞计数
        log.info("======================开始处理白细胞计数原数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 8)
        # 中性粒细胞数
        log.info("======================开始处理中性粒细胞数数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 9)
        # 血小板计数
        log.info("======================开始处理血小板计数数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 10)
        # C反应蛋
        log.info("======================开始处理C反应蛋数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 11)
        # 乳酸
        log.info("======================开始处理乳酸数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 12)
        # 氧饱和度
        log.info("======================开始处理氧饱和度数据==========================")
        utils.get_excel_data_by_sequentially_processed(excel_data, row_index, days, types, start_col, 13)


if __name__ == '__main__':
    # file_url 文件地址
    file_url = "/Users/wangweijie/workspace/data/ndz_data_20211211.xlsx"
    # sheet_name 需要操作的sheet名称
    sheet_name = "ndzList"
    #  获取需要操作的数据
    wb = load_workbook(file_url, data_only=True)
    data = wb[sheet_name]
    # data 数据不用担心
    # days 数据时序天数
    # types 数据类型总数
    # start_col 信息起始列数
    # 病人基础数据
    _user_vital_signs(data, 14, 7, 24)
    #  处理病人生化指标
    biochemical_index(data, 14, 14, 122)
    wb.save('脓毒症_插值.xlsx')

# def __get_user_info_list(excel_data):
#     """
#     获取病人信息集合
#     :param excel_data: excel处理对象
#     :return:  病人信息集合
#     """
#     #  病人信息集合
#     user_info_list = []
#     # 遍历病人信息列
#     for row_index in range(data_row_start, data_row_end + 1, 1):
#         user_info = UserInfoBean()
#         user_info.rows_index = row_index
#         # 病人名称
#         user_info.name = str(excel_data.cell(column=2, row=row_index).value)
#         user_info.sex = str(excel_data.cell(column=3, row=row_index).value)
#         user_info.age = str(excel_data.cell(column=4, row=row_index).value)
#         user_info.diagnosis_1 = str(excel_data.cell(column=5, row=row_index).value)
#         user_info.diagnosis_2 = str(excel_data.cell(column=6, row=row_index).value)
#         user_info.diagnosis_3 = str(excel_data.cell(column=7, row=row_index).value)
#         user_info.to_ice_date = str(excel_data.cell(column=8, row=row_index).value)
#         user_info.is_ards = str(excel_data.cell(column=9, row=row_index).value)
#         user_info.is_mechanical_ventilation = str(excel_data.cell(column=10, row=row_index).value)
#         user_info.mentality = str(excel_data.cell(column=11, row=row_index).value)
#         user_info.height = str(excel_data.cell(column=12, row=row_index).value)
#         user_info.weight = str(excel_data.cell(column=13, row=row_index).value)
#         user_info.bmi = str(excel_data.cell(column=14, row=row_index).value)
#         user_info.apache_score = str(excel_data.cell(column=15, row=row_index).value)
#         user_info.sofa_score = str(excel_data.cell(column=16, row=row_index).value)
#         user_info.pn_or_en = str(excel_data.cell(column=17, row=row_index).value)
#         user_info.total_time = str(excel_data.cell(column=18, row=row_index).value)
#         user_info.icu_total_time = str(excel_data.cell(column=19, row=row_index).value)
#         user_info_list.append(user_info)
#     return user_info_list
